package agile.hustler.activities;

import java.util.Scanner;


import agile.hustler.activities.R;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.ViewGroup;

public class StatsPopup extends Activity {
    /** Called when the activity is first created. */
	TextView Name;
	TextView txtClass;
	TextView Lvl;
	TextView Money;
	TextView XP;
	TextView AP;
	TextView HP;
	TextView Luck;
	TextView Effect;
	
	Toast toastMoney;
	Toast toastActionPoint;
	Toast toastLuck;
	Toast toastEffekt;
	Toast toastHp;
	Toast toastXp;

	TextView text;

	
	String spelarTyp, name, level, actionPoint, luck, effekt, xp, money;
	String data;
	
	int hp;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stats_popup);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        
        Bundle b = getIntent().getExtras();
        data = b.getString("key");
        
        toastMoney = Toast.makeText(this, "", 1500);   
		toastActionPoint = Toast.makeText(this, "", 1000);   
		toastLuck = Toast.makeText(this, "", 1500);   
		toastEffekt = Toast.makeText(this, "", 1500);   
		toastHp = Toast.makeText(this, "", 1500);   
		toastXp = Toast.makeText(this, "", 1500); 
        
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.toast,(ViewGroup) findViewById(R.id.toast1));
		
        Scanner scanner = new Scanner(data);
	    scanner.useDelimiter(" ");
	   // while ( scanner.hasNext() ){
	       spelarTyp = scanner.next();
	       name = scanner.next();
	       level = scanner.next();
	       actionPoint = scanner.next();
	       luck = scanner.next();
	       effekt = scanner.next();
	       hp = (int)Float.parseFloat(scanner.next());
	       xp = scanner.next();
	       money = scanner.next();
	       
	   // } 

	    Name = (TextView)findViewById(R.id.TextName);
	    txtClass = (TextView)findViewById(R.id.TextClass);
	    Lvl = (TextView)findViewById(R.id.TextLevel);
	    XP = (TextView)findViewById(R.id.TextXp);
	    Money = (TextView)findViewById(R.id.TextMoney);
	    AP = (TextView)findViewById(R.id.TextAp);
	    HP = (TextView)findViewById(R.id.TextHp);
	    Luck = (TextView)findViewById(R.id.TextLuck);
	    Effect = (TextView)findViewById(R.id.TextEffect);
	    
	    
	    Typeface face=Typeface.createFromAsset(getAssets(), "fonts/SEVERINA.ttf");
	    Typeface face2=Typeface.createFromAsset(getAssets(), "fonts/Comic Book.ttf");
	    

	    Name.setText(name);	
	    Name.setTypeface(face);
	    
	    txtClass.setText(spelarTyp);	
	    txtClass.setTypeface(face);

	    Lvl.setText("Level: " + level);	
	    Lvl.setTypeface(face);
	    
	    XP.setText(xp + " / " + 100*(int)Math.ceil(Math.pow(Float.parseFloat(level),2)/2.0));	
	    XP.setTypeface(face); 

	    Money.setText(money);	
	    Money.setTypeface(face); 
	    
	    AP.setText(actionPoint);	
	    AP.setTypeface(face); 
	    
	    HP.setText(Integer.toString(hp)); 	
	    HP.setTypeface(face);
	    
	    Luck.setText(luck);	 	
	    Luck.setTypeface(face);
	    	
	    Effect.setText(effekt);	
	    Effect.setTypeface(face); 
	    

	    text = (TextView) layout.findViewById(R.id.text);
		text.setTypeface(face2);
		
		
		toastMoney.setView(layout);
		toastActionPoint.setView(layout);
		toastLuck.setView(layout);
		toastEffekt.setView(layout);
		toastHp.setView(layout);
		toastXp.setView(layout);
	    
		findViewById(R.id.Moneybut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Money: Use in store to buy upgrade for your character ");
				toastMoney.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastMoney.show();	 
			}
		}
		);

		findViewById(R.id.ActionPointBut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Action point: Determine who get the first punch, also the rate of double punches");
				toastActionPoint.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastActionPoint.show();	 
			}
		}
		);

		findViewById(R.id.LuckBut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Luck: Determine how often you hit harder than usual ");
				toastLuck.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastLuck.show();	 
			}
		}
		);

		findViewById(R.id.EffektBut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Effect: The damage of your punch and kick                      ");
				toastEffekt.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastEffekt.show();	 
			}
		}
		);

		findViewById(R.id.Hpbut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Hp: How much health your character has                        ");
				toastHp.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastHp.show();	 
			}
		}
		);

		findViewById(R.id.Xpbut).setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) {
				text.setText("Xp: Experience which determine your level             ");
				toastXp.setGravity(Gravity.TOP|Gravity.LEFT, 40, 150);
				toastXp.show();	 
			}
		}
		);
	    
        findViewById(R.id.ButtonBack).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		Bundle B = new Bundle();

      		  B.putString("key", data);
      		
      		  
      		  Intent intent = new Intent(StatsPopup.this, CharacterScreen.class);

      		  intent.putExtras(B);
      		  
      		  startActivity(intent);
      		  finish();
      		System.gc();
        	}
        });
    }
}